<template>
  <div class="header_con">
    <div class="header">
      <div class="welcome fl">尊敬的用户:<a href="#/personal" v-if="user != null">{{ user.nickname }}</a> &nbsp;欢迎来到天天生鲜!
      </div>
      <div class="fr">
        <div class="login_info fl">
          欢迎您：<em></em>
        </div>
        <div class="login_btn fl">
          <a href="#/login" v-if="user == null">登录</a>
          <a v-if="user != null" @click="loginout">退出</a>
          <span v-if="user == null">|</span>
          <a href="#/register" v-if="user == null">注册</a>
        </div>
        <div class="user_link fl">
          <span>|</span>
          <a href="#/home">首页</a>
          <span>|</span>
          <a href="#/chat">联系客服</a>
          <span>|</span>
          <a href="#/personal">用户中心</a>
          <span>|</span>
          <a href="#/cart">我的购物车</a>
          <span>|</span>
          <a href="#/myorder">我的订单</a>
          <span v-if="user != null">|</span>
          <a href="#/history" v-if="user != null">浏览历史</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script>


export default {
  name: "Header",
  data() {
    return {
      user: "",
    }
  },
  methods: {
    loginout() {

      sessionStorage.clear();
      this.$router.push({
        path: '/login'
      })
      this.user = null;
    }
  },
  created() {
    this.user = JSON.parse(window.sessionStorage.getItem("user"));
  }
}
</script>